import {Application, RemoterClass, FrontendSession, ChannelService} from 'pinus';
import { PlayerService } from '../../../services/player_service';
import { User } from '../../../entity/user.entity';
import { Player } from '../../../entity/player.entity';

export default function (app: Application) {
    return new FightRemoter(app);
}

// UserRpc的命名空间自动合并
declare global {
    interface UserRpc {
        fight: {
            // 一次性定义一个类自动合并到UserRpc中
            fight_remote: RemoterClass<FrontendSession, FightRemoter>;
        };
    }
}


export class FightRemoter {

    _channelName="fight";
    
    constructor(private app: Application) {
  
      
    }

    public async add(player:Player,sid:string){
        let pNew=Object.assign(new Player(),player);
        console.log(pNew.name);
        PlayerService.ins().addPlayer(pNew);
        let channel= this.app.channelService.getChannel(this._channelName,true);
        channel.add(player.userId+"",sid);
        return;
    }

     
    public async kick(player:Player,sid:string) {
        let channel = this.app.channelService.getChannel(this._channelName, false);
        // leave channel
        if (!!channel) {
            channel.leave(""+player.userId, sid);
        }
        
    }

   
}